package com.sense.kukoo.common.wiget.dialog

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import com.sense.kukoo.common.R
import com.sense.kukoo.common.anim.BottomMotionAnimHelper
import com.sense.kukoo.common.utils.ApplicationContext

class MediaShareDialog:Dialog {

    private val TAG: String = javaClass.simpleName
    constructor(context: Context) : super(context)
    constructor(context: Context, themeResId: Int) : super(context, themeResId)
    constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener?) : super(context, cancelable, cancelListener)

    companion object{
        val TYPE_FACEBOOK = 0
        val TYPE_LINE = 1
        val TYPE_COPY_LINK = 2
    }

    private val mBottomMotionAnimHelper = BottomMotionAnimHelper()
    private var mListener: (Int)->Unit = {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context.setTheme(R.style.bottom_dialog)
        setContentView(R.layout.common_dialog_media_share)
        //
        val iv_btn_close = findViewById<View>(R.id.iv_btn_close)
        iv_btn_close.setOnClickListener {
            dismiss()
        }
        val fl_setting_root = findViewById<View>(R.id.fl_share_root)
        val cl_setting_content = findViewById<View>(R.id.cl_share_content)
        val first = ApplicationContext.dp2px(332F).toFloat()
        mBottomMotionAnimHelper.setAnimateDuration(200L)
        mBottomMotionAnimHelper.init(fl_setting_root, cl_setting_content, first){
            _dismiss()
        }
        //
        findViewById<View>(R.id.click_item_fackbook).setOnClickListener {
            dismiss()
            mListener(TYPE_FACEBOOK)
        }
        findViewById<View>(R.id.click_item_line).setOnClickListener {
            dismiss()
            mListener(TYPE_LINE)
        }
        findViewById<View>(R.id.click_item_copy_link).setOnClickListener {
            dismiss()
            mListener(TYPE_COPY_LINK)
        }
    }

    fun setListener(l: (Int)->Unit):MediaShareDialog{
        mListener = l
        return this
    }

    override fun show() {
        super.show()
        mBottomMotionAnimHelper.animateToStart()
    }

    override fun dismiss() {
        mBottomMotionAnimHelper.animateToFinish()
    }

    private fun _dismiss() {
        super.dismiss()
    }
}